package 设计模式.创建型.singleton单例;

/**
 * 单例模式
 */
public class SingleUser {

    public static volatile SingleUser user = null;

    /**
     * 无参构造
     */
    public SingleUser() {
    }

    public static SingleUser getInstance() {
        if (user == null) {
            synchronized (SingleUser.class) {
                if (user == null) {
                    user = new SingleUser();
                }
            }
        }

        return user;//已经实例化过了
    }

    public void test(int threadID) {
//        synchronized (SingleUser.class) {
            System.out.println("threadID = "+threadID+" "+Thread.currentThread().getName());
//        }
    }
}
